import axios from "axios";

axios.defaults.baseURL = 'http://127.0.0.1:8080';
axios.defaults.headers.post['Content-Type'] = 'application/json';
axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*';
axios.defaults.timeout = 1000;
axios.defaults.withCredentials = true;

/**
 * axios请求拦截
 * */
axios.interceptors.request.use(
    config => {
        // config.headers.Authorization = ''

        return config;
    },
    error => {
        return Promise.reject(error);
    }
);

/**
 * axios响应拦截
 * */
axios.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return Promise.resolve(response.data);
        } else {
            return Promise.reject(response.data);
        }
    },
    error => {
        console.log(JSON.stringify(error), '请求异常', {
            confirmButtonText: '确定',
        });
    }
);

export default axios
